package com.monika.main.system.domain;


import com.alibaba.fastjson2.JSON;
/**
 * @Author whh
 * @Date: 2023/04/15/ 1:47
 * @description
 */
public class AjaxResult {


    /**
     * 响应编码
     */
    private int code;

    /**
     * 响应数据
     */
    private Object data;

    /**
     * 消息
     */
    private String message;


    private long timestamp;


    private AjaxResult(AjaxResultStatus status, Object data, String message) {
        this.code = status.code;
        this.data = data;
        this.message = message;
        this.timestamp = System.currentTimeMillis();
    }

    /**
     *
     * @param data
     * @param message
     * @param <T>
     * @return
     */
    public static <T> AjaxResult success(T data, String message) {
       return new AjaxResult(AjaxResultStatus.SUCCESS,data, message);
    }



    public static <T> AjaxResult success(){
        return new AjaxResult(AjaxResultStatus.SUCCESS,null,AjaxResultStatus.SUCCESS.description);
    }



    public static <T> AjaxResult success(String message){
        return new AjaxResult(AjaxResultStatus.SUCCESS,null,message);
    }




    public static <T> AjaxResult fail(){
        return new AjaxResult(AjaxResultStatus.FAIL,null,AjaxResultStatus.FAIL.description);
    }

    public static <T> AjaxResult fail(T data,String message){
        return new AjaxResult(AjaxResultStatus.FAIL,data,message);
    }




    public static <T> AjaxResult fail(String message){
        return new AjaxResult(AjaxResultStatus.FAIL,null,message);
    }


    public static <T> AjaxResult exception(){
        return new AjaxResult(AjaxResultStatus.ERROR,null,AjaxResultStatus.ERROR.description);
    }



    public static <T> AjaxResult exception(String message){
        return new AjaxResult(AjaxResultStatus.ERROR,null,message);
    }


    public static <T> AjaxResult exception(T data,String message){
        return new AjaxResult(AjaxResultStatus.ERROR,data,message);
    }



    public String ajaxResultJson(){
        return JSON.toJSONString(this);
    }


    public int getCode() {
        return code;
    }

    public Object getData() {
        return data;
    }

    public String getMessage() {
        return message;
    }

    public long getTimestamp() {
        return timestamp;
    }
}
